<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="multiface.awwadco.jpa.Prodotto"%>
<%@page import="javax.persistence.EntityManager"%>
<%@page import="multiface.awwadco.jpa.PersistenceManager"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%
    EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
    EntityManager em = emf.createEntityManager();
    Prodotto p = em.find(Prodotto.class, Integer.parseInt(request.getParameter("pid")));
    em.refresh(p);
%>
<script type="text/javascript" src="../../engine/js/jquery.min.js"></script>
<script>
    function sendmail(){
        var test = true;
        if($("#nome").val() == ''){
            $("#err_nome").css("display","block");
            test = false;
        }
        if($("#cognome").val() == ''){
            $("#err_cognome").css("display","block");
            test = false;
        }
        if($("#email").val() == ''){
            $("#err_email").css("display","block");
            test = false;
        }
        if($("#richiesta").val() == ''){
            $("#err_richiesta").css("display","block");
            test = false;
        }
        
        if(test){
            var arr ={
                email           : $('#email').val(),
                nome            : $("#nome").val(),
                cognome         : $('#cognome').val(),
                telefono        : $('#telefono').val(),
                azienda         : $('#azienda').val(),
                richiesta         : $('#richiesta').val(),
                prodotto        : '<%=p.getNome()%>',
                prodotto_code       : '<%=p.getCodice()%>'
            }
        
            var loader_img = "<form><div class=\"title\">Request Information for <%=p.getNome()%> </div><div id=\"loader\"><img src=\"../../engine/img/loading3.gif\"></img></div></form>";
            $('#form-div').html(loader_img);
        
            $.post('../../SendMailServlet',arr, function(data) {
                if($.trim(data)=="PASS"){
                    $('#form-div').html("<form><div class=\"title\">Request Information for <%=p.getNome()%></div><div id=\"loader\">Request sent</div></form>");
                }else{
                    $('#form-div').html("Error : \n" + data);
                }
            })
        }
    }
</script>
<style>
    form{
        font-size: 9pt;
        font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
        margin:0;
        padding:0;
        color:black;
        width: 100%;
        float: left;
        border: 1px #ddd solid;
        margin-bottom: 8px;
    }
    .title{
        color: #3d3d3d;
        font-weight: bold;
        padding:6px;
        border-bottom: 2px #ddd solid;
        background-color: #ededed;
        font-size: 14px;
    }
    .privacy{font-size: 9px;color: #bbb;}
    .tit{width: 100px;float:left;}
    input{
        padding: 2px;
        border: 1px #ccc solid;
        width: 200px;
    }
    .row{
        margin: 8px;float: left;
    }
    #loader{
        padding: 20px;
        text-align: center;
    }
    .send-request{
        margin-left:200px;
        margin-top: 16px;
        margin-bottom: 16px;
    }
    .error{
        width: 200px;
        color: red;
        font-weight: bold;
        float: left;
        padding: 2px;
        display: none;
    }
    .testo_input{
        float: left;
    }
</style>

<html>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <body>
        <div id="form-div" class="news">
            <form name="contattaci" method="post" action="javascript:sendmail();">
                <div class="title">Request Information for "<%=p.getNome()%>"</div>
                <br>
                <div class="row"><div class="tit">Name: *</div><input id="nome" value="" class="testo_input" type="text"><div id="err_nome" class="error"> *Name is Required</div></div>
                <div class="row"><div class="tit">Surname: *</div><input id="cognome" value="" class="testo_input" type="text"><div id="err_cognome" class="error"> *Surname is Required</div></div>    
                <div class="row"><div class="tit">Email: *</div><input id="email" value="" class="testo_input" type="text"><div id="err_email" class="error"> *Email is Required</div></div>
                <div class="row"><div class="tit">Phone:</div><input id="telefono" value="" class="testo_input" type="text"></div>
                <div class="row"><div class="tit">Company:</div><input id="azienda" value="" class="testo_input" type="text"></div>
                <div class="row"><div class="tit">Request: *</div><textarea id="richiesta" cols="45" rows="6" name="richiesta" class="testo_input" type="text"></textarea><div id="err_richiesta" class="error"> *Request is Required</div></div>
                
                <input class="send-request" type="submit" value="Send Request"/>
            </form>
        </div>
    </body>
</html>

<%
    em.close();
%>